﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThanhTu.GNC.Media.KQXS.DataAccess.DAL;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;
using ThanhTu.GNC.Media.KQXS.DataAccess.BL;
using System.Data;

namespace GNCMedia.KQXS.Admin
{
    public partial class ModifiedHomePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                StyleLotteryBL vstyleLottery = new StyleLotteryBL();
               
                foreach (DataRow item in vstyleLottery.SelectAll().Rows)
                {
                    DropDownList1.Items.Add(item["POSITION"].ToString());
                }
                fuHomePage.Visible = true;
                txt_buttom.Visible = false;
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedItem.Text.Equals("buttom"))
            {
                fuHomePage.Visible = false;
                txt_buttom.Visible = true;
            }
            else
            {
                fuHomePage.Visible = true;
                txt_buttom.Visible = false;
            }

           
        }

        protected void btn_addNewData_Click1(object sender, EventArgs e)
        {

            StyleLotteryDAL styleHomePageDAL = new StyleLotteryDAL();
            StyleLotteryDO styleHomePageDO = new StyleLotteryDO();

            if (DropDownList1.SelectedItem.Text.Equals("buttom"))
            {
                styleHomePageDO.Settingname = txt_settingName.Text;
                styleHomePageDO.Settingtype = txt_settingtype.Text;
                styleHomePageDO.Position = DropDownList1.SelectedValue;
                styleHomePageDO.Settingvalue = txt_buttom.Text;
                int checkUpdate = styleHomePageDAL.update(styleHomePageDO);
                if (checkUpdate > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thành công ');", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thất bại');", true);
                }
            }
            else
            {
                styleHomePageDO.Settingname = txt_settingName.Text;
                styleHomePageDO.Settingtype = txt_settingtype.Text;
                styleHomePageDO.Position = DropDownList1.SelectedValue;
                fuHomePage.SaveAs(Server.MapPath("images") + "//" + fuHomePage.FileName);
                styleHomePageDO.Settingvalue = "../Admin/images/" + fuHomePage.FileName.ToString();
                int checkUpdate = styleHomePageDAL.update(styleHomePageDO);
                if (checkUpdate > 0)
                {

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thành công ');", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowStatus", "javascript:alert('Chỉnh sửa giao diện thất bại');", true);
                }
            }
        }
    }
}